package com.example.campus.mapper;


import com.example.campus.pojo.dto.AdminPageQueryDTO;
import com.example.campus.pojo.dto.AdminStatusChangeDTO;
import com.example.campus.pojo.dto.AdminUpdateDTO;
import com.example.campus.pojo.entity.Admin;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;


@Mapper
public interface AdminMapper {

    /**
     * 根据用户名查询管理员
     * @param username
     * @return
     */
    @Select("select * from admin where username = #{username}")
    Admin getByUsername(String username);

    /**
     * 根据id查询管理员
     * @param adminId
     * @return
     */
    @Select("select * from admin where id = #{adminId}")
    Admin getByAdminId(Long adminId);

    /**
     * 插入管理员数据
     * @param admin
     */
    @Insert("insert into admin (name, username, password, phone, email, sex, create_time, update_time) " +
            "values " +
            "(#{name}, #{username}, #{password}, #{phone}, #{email}, #{sex}, #{createTime}, #{updateTime})")
    void insert(Admin admin);

    /**
     * 根据id删除管理员
     * @param adminId
     */
    @Delete("delete from admin where id = #{adminId}")
    void deleteById(Long adminId);

    /**
     * 管理员分页查询
     * @param adminPageQueryDTO
     * @return
     */
    Page<Admin> pageQuery(AdminPageQueryDTO adminPageQueryDTO);

    /**
     * 更新管理员信息
     * @param adminUpdateDTO
     */
    @Update("update admin set username = #{username}, name = #{name}, phone = #{phone}, email = #{email}, sex = #{sex}, update_time = now() where id = #{id}")
    void update(AdminUpdateDTO adminUpdateDTO);

    /**
     * 修改已登录管理员的密码
     * @param newPwd
     * @param adminId
     */
    @Update("update admin set password = #{newPwd} where id = #{adminId}")
    void updatePwd(String newPwd, Long adminId);

    /**
     * 修改管理员状态
     * @param adminStatusChangeDTO
     */
    @Update("update admin set status = #{status} where id = #{adminId}")
    void changeAdminStatus(AdminStatusChangeDTO adminStatusChangeDTO);
}
